#include<iostream>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<unistd.h>
using namespace std;

#define BACKLOG 2
#define PORT 8080

int main(){
    int lsock = socket(AF_INET,SOCK_STREAM,0);
    if(lsock == 0){
        cerr<<"socket error!"<<endl;
        return 1;
    }
    int opt = 1;
    setsockopt(lsock,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));
    struct sockaddr_in local;
    local.sin_family = AF_INET;
    local.sin_port = ntohs(PORT);
    local.sin_addr.s_addr = INADDR_ANY;

    if(bind(lsock,(struct sockaddr*)&local,sizeof(local)) < 0){
        cerr<<"bind error"<<endl;
        return 2;
    }

    if(listen(lsock,BACKLOG) < 0){
        cerr<<"listen error"<<endl;
        return 3;
    }
    while(1){
        sleep(1);
    }  
    return 0;
}
